home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / timer.c < prev   
C/C++ Source or Header  |  1989-09-16  |  3KB  |  77 lines

  1. /* Timer.c - Timer support routines */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  5. /* |. o.| || This program may not be distributed without the permission of   */
  6. /* | .  | || the author.                                           BBS:      */
  7. /* | o  | ||   John Toebes    Dave Baker                     (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11. #define NETCOMMON
  12. #include "netcomm.h"
  13. #include "proto.h"
  14.  
  15. int OpenTimer(global, port)
  16. NGLOBAL global;    
  17. struct MsgPort *port;
  18. {
  19.    int error;
  20.  
  21.    /* assumes that a msg port has been allocated */   
  22.  
  23.    if ((global->n.timerpkt = (struct TimerPacket *)
  24.                 CreateExtIO(port, sizeof(struct TimerPacket)))== NULL)
  25.      return(1);
  26.  
  27.    global->n.timerpkt->tm_req.tr_node.io_Message.mn_Node.ln_Name = 
  28.                               (char *)&(global->n.timerpkt->tm_pkt);
  29.    global->n.timerpkt->tm_pkt.dp_Link =
  30.                      &(global->n.timerpkt->tm_req.tr_node.io_Message);
  31.    global->n.timerpkt->tm_pkt.dp_Port = port;
  32.  
  33.    error = OpenDevice(TIMERNAME, UNIT_MICROHZ, 
  34.                      (struct IORequest *)&(global->n.timerpkt->tm_req), 0);
  35.  
  36.    return(error);
  37. }
  38.  
  39. void CloseTimer(global)
  40. NGLOBAL global;
  41. {
  42.    if (global->n.timerpkt != NULL)
  43.       {
  44.       CloseDevice((struct IORequest *)&(global->n.timerpkt->tm_req));
  45.       DeleteExtIO((struct IORequest *)global->n.timerpkt,
  46.                    sizeof(struct TimerPacket));
  47.       global->n.timerpkt = NULL;
  48.       }
  49.  
  50. }
  51.  
  52. void PostTimerReq(global, time)
  53. NGLOBAL global;
  54. int time;  /* tenths of a second */
  55. {
  56.    /* Fill in the timer packet values */
  57.    /* that is the fields required for the timer device timerequest struct */
  58.    /* and the necessary fields of the DosPacket struct                    */
  59.    /* nothing like using 35 meg of store to accomplish a simple task      */
  60.    /* oh well ! this is a 68K machine right ?                             */ 
  61.    /* some of them get trampled on so fill them all */
  62.  
  63.    if (global->n.timerpkt != NULL)
  64.       {
  65.       time *= 100000;
  66.       global->n.timerpkt->tm_req.tr_node.io_Command = TR_ADDREQUEST;
  67.       global->n.timerpkt->tm_req.tr_time.tv_secs = time/100000;
  68.       global->n.timerpkt->tm_req.tr_time.tv_micro = time%100000;
  69.  
  70.       global->n.timerpkt->tm_pkt.dp_Type = ACTION_TIMER;
  71.       
  72.       /* Async IO so we don't sleep here for the msg */
  73.      
  74.       SendIO((struct IORequest *)&global->n.timerpkt->tm_req);
  75.       }
  76. }
  77.